package com.yxx.controller.admin;

import com.yxx.mapper.MedicineCategoryMapper;
import com.yxx.medicinecommon.result.PageResult;
import com.yxx.medicinecommon.result.ResponseResult;
import com.yxx.medicinepojo.dto.Medicine_CategoryDTO;
import com.yxx.medicinepojo.dto.Medicine_Category_PageQueryDTO;
import com.yxx.medicinepojo.entity.Medicine_Category;
import com.yxx.medicinepojo.entity.SetMedicine;
import com.yxx.service.MedicineCategoryService;
import com.yxx.service.SetMedicineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类管理
 * @author yuxiangxun
 * @date 2024/9/7
 * @apiNote
 */
@Slf4j
@RestController("adminMedicineCategoryController")
@Api(tags = "分类管理")
@RequestMapping("/admin/category")
public class MedicineCategoryController {

    @Autowired
    private MedicineCategoryService medicineCategoryService;
    @GetMapping("/page")
    @ApiOperation("分页管理分页查询")
    public ResponseResult<PageResult> Category_Page(Medicine_Category_PageQueryDTO medicineCategoryPageQueryDTO){
        PageResult pageResult = medicineCategoryService.page(medicineCategoryPageQueryDTO);
        return ResponseResult.success(pageResult);
    }

    @PutMapping
    @ApiOperation("分类修改")
    public ResponseResult update(@RequestBody Medicine_CategoryDTO medicineCategoryDTO){
        medicineCategoryService.update_Category(medicineCategoryDTO);
        return ResponseResult.success();
    }

    @PostMapping("/status/{status}")
    @ApiOperation("分类启用/禁用")
    public ResponseResult Category_Start_Disable(
            @ApiParam(value = "状态 0:启用 1:禁用", required = true) @PathVariable("status") Integer status,
            @ApiParam(value = "分类id", required = true) Long id) {
        medicineCategoryService.Category_Start_Disable(status,id);
        return ResponseResult.success();
    }

    @GetMapping("/list")
    @ApiOperation("根据类型查询分类列表")
    public ResponseResult<List<Medicine_Category>> TypeList(Integer type){
        List<Medicine_Category> typeList = medicineCategoryService.typeList(type);
        log.info("typeList:{}",typeList);
        return ResponseResult.success(typeList);
    }

    @PostMapping
    @ApiOperation("新增分类")
    public ResponseResult insert_Medicine_Category(@RequestBody Medicine_CategoryDTO medicineCategoryDTO){
        medicineCategoryService.insert_Medicine_Category(medicineCategoryDTO);
        return ResponseResult.success();
    }

    @DeleteMapping
    @ApiOperation("删除分类")
    public ResponseResult delete_Medicine_Category_id(Long id){
        medicineCategoryService.delete_Medicine_Category_id(id);
        return ResponseResult.success();
    }


}
